import org.junit.Test;
import org.omg.CORBA.portable.ValueOutputStream;
import sun.applet.Main;

/**
 * @author jcl_hqu
 * @date 2021/4/6 20:27
 */
public class MyThread extends Thread {
    public static void main(String[] args) {
        ShareData task = new ShareData();
        MyThread myThread=new MyThread(){
            @Override
            public void run(){
                try {
                    task.consumer();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        MyThread myThread1=new MyThread(){
            @Override
            public void run(){
                try {
                    task.producer();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        for (int i=0;i<3;i++) {
            myThread.start();
            myThread1.start();
        }
    }
    @Test
    public void test() throws InterruptedException {
        Thread t1=new Thread();
        Thread t2=new Thread();
        t1.setName("thread1");
        t2.setName("thread2");
        t1.start();
        t2.start();
        t2.interrupt();
        System.out.println(t2.isInterrupted());
        System.out.println(t2.isInterrupted());
        ThreadGroup currentGroup =
                Thread.currentThread().getThreadGroup();
        int noThreads = currentGroup.activeCount();
        Thread[] lstThreads = new Thread[noThreads];
        currentGroup.enumerate(lstThreads);
        for (int i = 0; i < noThreads; i++)
            System.out.println("线程号：" + i + " = " + lstThreads[i].getName());
    }
}
